package Classes
{
	import flash.display.BitmapDataChannel;
	import flash.events.Event;
	import flash.geom.Point;
	
	public class pi_TransparentJPG extends Object {
		public function pi_TransparentJPG() {
			super();
		}
		
		public static function load(filePath: String, fileMaskPath: String, app: Object, onComplete: Function): void {
			var l_tmpl		: Object;
			var l_mask		: Object;
			var _jpgBitmap	: Object; 
			
			function l_doLoad(e: Event): void {
				if (l_tmpl.loaded && l_mask.loaded) {
					var size: Point = new Point(l_tmpl.contentLoaderInfo.width, l_tmpl.contentLoaderInfo.height);
					
					_jpgBitmap = new app.classes.bitmap();
					_jpgBitmap.bitmapData = new app.classes.bitmapData(size.x, size.y);
					_jpgBitmap.bitmapData.draw(l_tmpl);
					
					var bmdMask: Object = new app.classes.bitmapData(size.x, size.y, true, 0xFFFFFF);
					bmdMask.draw(l_mask);
					_jpgBitmap.bitmapData.copyChannel(bmdMask, bmdMask.rect, new Point(0, 0), BitmapDataChannel.BLUE, BitmapDataChannel.ALPHA);
					onComplete(_jpgBitmap, bmdMask);
				}
			}

			l_tmpl = new app.classes.loader(null, filePath, l_doLoad);
			l_mask = new app.classes.loader(null, fileMaskPath, l_doLoad);
		}
	}
}